<template>
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel">{{ $t('关闭') }}</a-button>
    </template>
    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="10" :lg="11" :md="12" :sm="24">
              <a-form-item :label="$t('时间')">
                <a-date-picker
                  :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :placeholder="$t('请选择开始时间')"
                  class="query-group-cust"
                  v-model="queryParam.createTime_begin"
                ></a-date-picker>
                <span class="query-group-split-cust"></span>
                <a-date-picker
                  :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                  valueFormat="YYYY-MM-DD HH:mm:ss"
                  :placeholder="$t('请选择结束时间')"
                  class="query-group-cust"
                  v-model="queryParam.createTime_end"
                ></a-date-picker>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('机号')">
                <a-input :placeholder="$t('请输入机号')" v-model="queryParam.machineNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="8" :lg="9" :md="10" :sm="24">
              <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
                <a @click="handleToggleSearch" style="margin-left: 8px">
                  {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                  <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
                </a>
                <a-button
                  style="margin-left: 50px"
                  type="primary"
                  :loading="exloading"
                  @click="handleExportXls($t('活动记录'))"
                  v-has="'BisGameCoinRecordController:export'"
                  >{{ $t('导出') }}</a-button
                >
              </span>
            </a-col>
            <template v-if="toggleSearchStatus">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item :label="$t('会员信息')">
                  <a-input :placeholder="$t('请输入会员手机号/卡号/姓名')" v-model="queryParam.memberInfo"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item :label="$t('投币类型')">
                  <a-select v-model="queryParam.inputType">
                    <a-select-option :value="item.value" :key="index" v-for="(item, index) in inputTypeList">{{
                      item.title
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item :label="$t('设备名称(编码)')">
                  <a-select show-search :filter-option="false" @search="handleSearch" v-model="queryParam.deviceId">
                    <a-select-option :value="item.id" :key="index" v-for="(item, index) in deviceList">
                      <span>{{ item.name }}</span>
                      <span v-if="item.name != $t('全部')">({{ item.id }})</span>
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item :label="$t('机台名称')">
                  <a-input :placeholder="$t('请输入机台名称')" v-model="queryParam.gameInfo"></a-input>
                </a-form-item>
              </a-col>
            </template>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- table区域-begin -->
      <div>
        <a-table
          ref="table"
          size="middle"
          :scroll="{ x: true }"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          class="j-table-force-nowrap"
          @change="handleTableChange"
        >
          <template slot="footer">
            <div style="font-weight: bold">
              <span style="margin-left: 15px; margin-right: 5px">{{ $t('投币值') }}：</span>
              <span>{{ totalInfo.coin }}</span>
            </div>
          </template>
        </a-table>
      </div>
    </a-card>
  </a-modal>
</template>

<script>
import '@/assets/less/TableExpand.less'
import moment from 'moment'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions, filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import { getAction, downFile } from '@/api/manage'

export default {
  name: 'GameActivityRecordModal',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      moment,
      deviceList: [],
      inputTypeList: [],
      // 表头
      columns: [
        {
          title: this.$t('时间'),
          align: 'center',
          dataIndex: 'createTime',
          width: 200,
          sorter: true,
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'memberPhone',
          width: 120,
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
          width: 120,
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'memberName',
          width: 120,
        },
        {
          title: this.$t('机号'),
          align: 'center',
          dataIndex: 'machineNo',
          width: 140,
        },
        {
          title: this.$t('机台名称'),
          align: 'center',
          dataIndex: 'gameId_dictText',
          width: 120,
        },
        {
          title: this.$t('投币类型'),
          align: 'center',
          dataIndex: 'inputType_dictText',
          width: 120,
        },
        {
          title: this.$t('投币值'),
          align: 'center',
          dataIndex: 'coin',
          width: 120,
        },
        {
          title: this.$t('设备编码'),
          align: 'center',
          dataIndex: 'deviceId',
          width: 140,
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          dataIndex: 'deviceName',
          width: 140,
        },
      ],
      url: {
        list: '/game/bisGameCoinRecord/list',
        exportXlsUrl: '/game/bisGameCoinRecord/exportXlsByActivity',
        totalUrl: 'game/bisGameCoinRecord/total',
      },
      isCustom: true,
      isfooter: true,
      title: this.$t('活动记录'),
      width: 1500,
      visible: false,
      confirmLoading: false,
      activityId: '',
    }
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      initDictOptions('bis_game.input_type').then((res) => {
        if (res.success) {
          this.inputTypeList = res.result
          this.inputTypeList.unshift({ value: '', title: this.$t('全部') })
        }
      })
      this.handleSearch('')
    },
    handleSearch(value) {
      let query = {}
      if (value) {
        query.deviceInfo = value
      }
      getAction('/device/bisDeviceInfo/list', query).then((res) => {
        if (res.success) {
          this.deviceList = res.result.records
          this.deviceList.unshift({ id: '', name: this.$t('全部') })
        }
      })
    },
    show(record) {
      this.visible = true
      this.activityId = record.id
      this.queryParam = {
        createTime_begin: moment().format('YYYY-MM-DD 00:00:00'),
        createTime_end: moment().format('YYYY-MM-DD 23:59:59'),
        inputType: '',
        deviceId: '',
        activityId: this.activityId,
      }
      this.loadData(1)
      this.initDictConfig()
    },
    handleCancel() {
      this.visible = false
    },
    searchReset() {
      this.queryParam = {
        createTime_begin: moment().format('YYYY-MM-DD 00:00:00'),
        createTime_end: moment().format('YYYY-MM-DD 23:59:59'),
        inputType: '',
        deviceId: '',
        activityId: this.activityId,
      }
      this.loadData(1)
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>